package com.zjuee.web.company.service.impl.handledata;

import com.zjuee.base.utils.DesensitizationUtil;
import com.zjuee.core.translation.handledata.impl.AbstractDataHandler;
import com.zjuee.service.company.vo.CompanyInfoVo;
import com.zjuee.base.model.common.company.Company;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author wu liang
 * @since 2020/10/10 14:30
 */
@Component(value = "corpInfoHandle")
public class CorpInfoHandle extends AbstractDataHandler {


    @Override
    public <T> T getData(T data, Map<Object,Object> map, String... str) {
        Company companyInfo = (Company) data;
        CompanyInfoVo companyInfoVo = new CompanyInfoVo();
        try {
            BeanUtils.copyProperties(companyInfo, companyInfoVo);
            companyInfoVo.setBciCode(DesensitizationUtil.desensitizedCodeNumber(companyInfoVo.getBciCode()));
            companyInfoVo.setBciLegalDelegate(
                    DesensitizationUtil.desensitizedName(companyInfoVo.getBciLegalDelegate()));
            companyInfoVo.setBciLegalDelegatePhone(
                    DesensitizationUtil.desensitizedPhoneNumber(companyInfoVo.getBciLegalDelegatePhone()));
            companyInfoVo.setBciEnvironDelegate(
                    DesensitizationUtil.desensitizedName(companyInfoVo.getBciEnvironDelegate()));
            companyInfoVo.setBciEnvironDelegatePhone(
                    DesensitizationUtil.desensitizedPhoneNumber(companyInfoVo.getBciEnvironDelegatePhone()));
            companyInfoVo.setBciGarbageDelegate(
                    DesensitizationUtil.desensitizedName(companyInfoVo.getBciGarbageDelegate()));
            companyInfoVo.setBciGarbageDelegatePhone(
                    DesensitizationUtil.desensitizedPhoneNumber(companyInfoVo.getBciGarbageDelegatePhone()));
            companyInfoVo.setBciRegisterMobile(
                    DesensitizationUtil.desensitizedPhoneNumber(companyInfoVo.getBciRegisterMobile()));
            if (companyInfo.getBciType() != null) {
                String[] corptypes = companyInfo.getBciType().split(",");
                String corpTypeCN = null;
                for (String corpType : corptypes) {
//                    if (!"1,4,7".contains(corpType)) {
//                        continue;
//                    }
                    if (corpTypeCN != null) {
                        corpTypeCN = corpTypeCN + "," + map.get(corpType + str[0] == null ? "" : corpType + str[0]);
                    } else {
                        corpTypeCN = map.get(corpType + str[0] == null ? "" : corpType + str[0]).toString();
                    }
                }
                if(",".equals(corpTypeCN)){
                    corpTypeCN = corpTypeCN.substring(0, corpTypeCN.length() - 1);
                }
                companyInfoVo.setBciTypeCN(corpTypeCN);
            }
            companyInfoVo.setBciTagCN(map.get(companyInfo.getBciTag() + "" + str[1]) == null?"" : map.get(companyInfo.getBciTag() + "" + str[1]).toString());
            companyInfoVo.setBciScaleCN(map.get(companyInfo.getBciScale() + "" +  str[2]) == null?"" : map.get(companyInfo.getBciScale() + "" +  str[2]).toString());
            companyInfoVo.setBciCategoryCN(map.get(companyInfo.getBciCategory() + "" + str[3]) == null?"" : map.get(companyInfo.getBciCategory() + "" + str[3]).toString());
            companyInfoVo.setBciBGroupCN(map.get(companyInfo.getBciBgroup() + "" + str[4]) == null?"" : map.get(companyInfo.getBciBgroup() + "" + str[4]).toString());
            companyInfoVo.setBciMGroupCN(map.get(companyInfo.getBciMgroup() + "" + str[5]) == null?"" : map.get(companyInfo.getBciMgroup() + "" + str[5]).toString());
            companyInfoVo.setBciSGroupCN(map.get(companyInfo.getBciSgroup() + "" + str[6]) == null?"" : map.get(companyInfo.getBciSgroup() + "" + str[6]).toString());
            companyInfoVo.setBciProvinceCN(map.get(companyInfo.getBciProvince() + "" + str[7]) == null?"" : map.get(companyInfo.getBciProvince() + "" + str[7]).toString());
            companyInfoVo.setBciCityCN(map.get(companyInfo.getBciCity() + "" + str[8]) == null?"" : map.get(companyInfo.getBciCity() + "" + str[8]).toString());
            companyInfoVo.setBciAreaCN(map.get(companyInfo.getBciArea() + "" + str[9]) == null?"" : map.get(companyInfo.getBciArea() + "" + str[9]).toString());
            String street = companyInfo.getBciStreet().length()>9?companyInfo.getBciStreet().substring(0,9):companyInfo.getBciStreet();
            companyInfoVo.setBciStreetCN(map.get(street  + "" + str[10]) == null?"" : map.get(street + "" + str[10]).toString());
            companyInfoVo.setBciIsUploadCN(map.get(companyInfo.getBciIsUpload() + "" + str[11]) == null?"" : map.get(companyInfo.getBciIsUpload() + "" + str[11]).toString());
            companyInfoVo.setBciStatusCN(map.get((companyInfo.getBciStatus()==1 ? 1 : 2) + "" + str[12]) == null?"" : map.get((companyInfo.getBciStatus()==1 ? 1 : 2) + "" + str[12]).toString());
            companyInfoVo.setBciAuditStatusCN(map.get(companyInfo.getBciAuditStatus() + "" + str[13]) == null?"" : map.get(companyInfo.getBciAuditStatus() + "" + str[13]).toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
        //查询数据
        return (T) companyInfoVo;
    }
}
